<#include "/common/layout.html">
<@body>
<body class="gray-bg">
	<div class="wrapper">
		<section class="content">
			<div class="box">
				<div class="form-inline">
					<div class="box-header">
						<#if shiro.hasPermission("editRole")>
							<div class="input-group">
								<a class="btn btn-sm btn-primary dialog" href="javascript:;"
								   data-url="${request.contextPath}/system/role/getUsers/${roleId}" data-title="选择角色"><i class="fa fa-plus"></i> 添加用户</a>
							</div>
						</#if>
						<div class="input-group">
							<a href="javascript:;" onclick="closeAssign()" class="btn btn-sm btn-default"><i class="fa fa-reply"></i> 关闭</a>
						</div>
					</div>
				</div>
				<div class="box-body">
					<input type="hidden" id="roleId" value="${roleId}" >
					<table id="roleUsers_initTable" class="table table-bordered table-hover"></table>
				</div>
			</div>
		</section>
	</div>
</body>
</@body>
<script>
	$(function(){
		initTable();
	}); 
	var query_data = {
		roleId: $("#roleId").val()
	}
	//渲染表格
	function initTable() {
		var options = {
			id: 'roleUsers_initTable',
			ajax: {
				url: "${request.contextPath}/system/role/assignUsers/listPage",
				type: "POST",
				data: query_data,
			},
			columnDefs: [{
				targets: 0,
				title: "用户名",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.userName != null) {
						return t.userName;
					} else {
						return "";
					}
				}
			},{
				targets: 1,
				title: "描述",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.userDesc != null) {
						return t.userDesc;
					} else {
						return "";
					}
				}
			},{
				targets: 2,
				title: "创建时间",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.createTime != null) {
						return t.createTime;
					} else {
						return "";
					}
				}
			},{
				targets: 3,
				title: "状态",
				orderable: !1,
				render: function(e, a, t, n) {
					if (t.userState == 1) {
						return '<font color="green">启用</font>';
					} else {
						return '<font color="red">禁用</font>';
					}
				}
			},{
				targets: 4,
				title: "操作",
				orderable: !1,
				render: function(e, a, t, n) {
					var html = '<a class="btn btn-danger btn-xs" onclick="cancelAssign('+ t.userId +')" title="取消授权"><i class="fa fa-trash"></i> 取消授权</a>';
					return html;
				}
			}]
		};
		//渲染表格
		data_oTable = $.table.init(options);
	}
	
	function closeAssign() {
		closeItem();
	}
	
	function cancelAssign(userId) {
		$.modal.confirm('您确定取消该用户授权吗?', function(index) {
			$.ajax({
				url : '${request.contextPath}/system/role/deleteAssignUser',
				type : 'POST',
				dataType : "json",
				data : {userId : userId, roleId : $("#roleId").val()},
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					if (data.code == 200) {
						if (data.msg) {
							parent.layer.msg(data.msg, {
								icon : 1
							});
						} else {
							parent.layer.msg('提交成功', {
								icon : 1
							});
						}
						data_oTable.draw(false);
						$.modal.closeLoading();
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		});
	}
</script>

